package com.explam.springboot.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultUtil {
    public static final String SUCCESS_CODE = "200";     // 成功
    public static final String ERROR_CODE = "400";       // 失败码
    public static final String ERROR_LOGIN_CODE = "401";       // 登录错误
    public static final String ERROR_SYSTEM_CODE = "500";      // 系统错误
    public static final String ERROR_AUTHORITY_CODE = "600";   // 权限不足
    public static final String SUCCESS_MESSAGE = "success";
    public static final String FAIL_MESSAGE = "error";

    /**
     * 状态码
     */
    protected String code;

    /**
     * 响应信息
     */
    protected String message;

    /**
     * 返回数据
     */
    private Object data;


    /*------------------------成功------------------------*/
    /**
     * 成功返回状态码、信息
     */
    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(SUCCESS_MESSAGE);
        return resultUtil;
    }
    /**
     * 成功返回信息
     */
    public static ResultUtil success(String msg) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(msg);
        return resultUtil;
    }
    /**
     * 成功返回数据
     */
    public static ResultUtil success(Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(SUCCESS_MESSAGE);
        resultUtil.setData(data);
        return resultUtil;
    }

    /**
     * 成功返回信息、数据
     */
    public static ResultUtil success(String msg, Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(msg);
        resultUtil.setData(data);
        return resultUtil;
    }

    /**
     * 成功返回状态码、信息、数据
     */
    public static ResultUtil success(String code, String msg,Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(code);
        resultUtil.setMessage(msg);
        resultUtil.setData(data);
        return resultUtil;
    }

    /*------------------------失败------------------------*/
    /**
     * 失败返回信息
     */
    public static ResultUtil error() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(SUCCESS_MESSAGE);
        return resultUtil;
    }
    /**
     * 失败返回信息
     */
    public static ResultUtil error(String msg) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(msg);
        return resultUtil;
    }
    /**
     * 失败返回数据
     */
    public static ResultUtil error(Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(SUCCESS_MESSAGE);
        resultUtil.setData(data);
        return resultUtil;
    }

    /**
     * 失败返回信息、数据
     */
    public static ResultUtil error(String msg, Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(SUCCESS_CODE);
        resultUtil.setMessage(msg);
        resultUtil.setData(data);
        return resultUtil;
    }

    /**
     * 失败返回信息、数据
     */
    public static ResultUtil error(String code, String msg) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(code);
        resultUtil.setMessage(msg);
        return resultUtil;
    }

    /**
     * 失败返回状态码、信息、数据
     */
    public static ResultUtil error(String code, String msg,Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(code);
        resultUtil.setMessage(msg);
        resultUtil.setData(data);
        return resultUtil;
    }

}
